// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: xguo

#include <memory>

#include "coin2/exchange/base/order/order.h"
#include "coin2/exchange/dydx_futures/api_util/auth_key.h"

using namespace coin2::exchange::base::order;

namespace {
using namespace starkware;
constexpr auto PRIVKEY = 0x0000000000000000000000000000000000000000000000000000000000000000_Z;
constexpr auto PUBKEY = 0x0000000000000000000000000000000000000000000000000000000000000000_Z;
}  // namespace

uint64_t NonceFromClientId(const std::string& data);

int main() {
  auto r = NonceFromClientId("12345");
  LOG(INFO) << "nonce from client id 12345 is " << r;

  std::string norm_product = "BTC-USD";
  ExchangeType exchange = coin::proto::Dydx;
  MarketType market_type = coin::proto::Futures;
  OrderType order_type = coin::proto::LIMIT_ORDER;
  OrderSide order_side = coin::proto::BUY_ORDER;
  OrderDuration duration = coin::proto::GTC_ORDER;
  double price = 66441;
  double qty = 0.005;
  int64_t order_created_time = 111231223123120;  // do not matter.
  bool post_only = false;
  bool reduce_only = false;
  double leverage_rate = 1;
  std::string tag = "";

  auto order = OrderSpec(
      norm_product,
      norm_product,
      exchange,
      market_type,
      order_type,
      order_side,
      duration,
      price,
      qty,
      order_created_time,
      post_only,
      reduce_only,
      leverage_rate,
      tag);

  order.proc_order_id = 1636523604191021478;
  order.order_expiration_ts = 1636524217.905 * 1e9;

  LOG(INFO) << order.ToProto().DebugString();

  auto so = StarkwareOrder(order);
  so.position_id = 133189;
  so.pub_key = PUBKEY;
  auto t1 = GetCurrentTimestamp();
  auto ha = so.CalculateHash();
  auto t2 = GetCurrentTimestamp();
  auto res = so.Sign(PRIVKEY);
  auto t3 = GetCurrentTimestamp();
  LOG(INFO) << ha;
  LOG(INFO) << PRIVKEY;
  LOG(INFO) << res;
  LOG(INFO) << (t2-t1)/1e9;
  LOG(INFO) << (t3-t2)/1e9;
  return 0;
}
